//
//  ClassroomController.swift
//  SchoolDemo
//
//  Created by rimi on 16/9/26.
//  Copyright © 2016年 YQ. All rights reserved.
//

import UIKit

class ClassroomController: HSBasicController {
    var dataSouce:[HSClassroomModal] = []
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        tableView.rowHeight = 100
        //注册圆形cell
        tableView.register(ClassroomTableViewCell.self, forCellReuseIdentifier: "classroomCell")
            loadData()
    }

    ///请求数据
    internal override func loadData() {
        guard let  key  = userInfo["key"] as?String else {
            return
        }
        
            /*String  key
             String  id(已存储的习题最小id， 下拉默认返回30条数据，上拉默认请求默认追加30数据)目前接口传的是stutentmessage表的主键id
             
             String   load_type(1下拉，2上拉)
             */
            let url = "ZH-schoolname-S-getNewMessage"
            
            
            let parame = ["key":key,"id":"0","loda_type":"1"] as [String : Any]
            
            HSNetWorkTools.shared.downloadData(url: url, parameters: parame) {[weak self] (data, err) in
                print("---------+++++++++",data,err)
                guard let data = data as? NSDictionary else {
                    HSAlertView.bottomAlertView("网络异常，请检查")
                    //网络加载失败通知处理器
              
                    return
                }
                let dataArray = (data as! [String:Any])["data"] as!NSArray
                for dic in dataArray {
                    let modal = HSClassroomModal(dict: dic as! [String : Any])
                    self?.dataSouce.append(modal)
                }
                self?.tableView.reloadData()
                
            }
            
        }

    

//MAKR:-tableview方法
    override func tableView(_ tableView: UITableView, cellForRowAt indexpath:IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "classroomCell", for: indexpath) as! ClassroomTableViewCell
        cell.selectionStyle = .none
        //赋值
        let model = dataSouce[indexpath.row]
        
        cell.classroomBtn.setTitle(model.course, for: .normal)
        cell.classtimeL.text = model.creattime
        cell.classteacherL.text = model.username
        cell.claccroomTitleL.text = model.picgroupname
        
        if  dataSouce[indexpath.row].userid == 0 {
            cell.classIconView.image = UIImage(named: "tgril")
        } else {
            cell.classIconView.image = UIImage(named: "tboy")
        }
        return cell
    }
    




    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return dataSouce.count
    }



}
